package com.yanqu.road.server.manger.config;

import com.yanqu.road.entity.config.travelbook.AlbumConfig;
import com.yanqu.road.entity.config.travelbook.CardConfig;
import com.yanqu.road.logic.config.GameConfig;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : Cxp
 * @Time : 2024-11-12
 * @Description : 旅行册配置
 */

public class TravelBookConfigMgr {

    public static Map<Integer, String> cardRecycleMap = null; // 星级 -> 回收道具

    /**
     * 获取卡牌配置
     *
     * @param cardId 卡牌ID
     * @return 卡牌配置
     */
    public static CardConfig getCardInfo(int cardId) {
        CardConfig cardConfig = GoodsMgr.getCardConfigMap().getOrDefault(cardId, null);

        if (cardConfig == null) {
            return null;
        }

        for (Map.Entry<Integer, AlbumConfig> kv : PatronsMgr.getAlbumConfigMap().entrySet()) {
            int albumId = kv.getKey();
            AlbumConfig albumConfig = kv.getValue();
            if (albumId == cardConfig.getAlbumId()) {
                cardConfig.setBeautyId(albumConfig.getBeautyId());
                cardConfig.setSkillInfo(SkillMgr.getSkillInfo(albumConfig.getCombInfo().getSkillId(cardId)));
            }
        }

        return cardConfig;
    }

    /**
     * 获取卡册配置
     *
     * @param albumId 卡册ID
     * @return 卡册配置
     */
    public static AlbumConfig getAlbumInfo(int albumId) {
        AlbumConfig albumConfig = PatronsMgr.getAlbumConfigMap().getOrDefault(albumId, null);

        if (albumConfig == null) {
            return null;
        }

        albumConfig.setSkillInfo(SkillMgr.getSkillInfo(albumConfig.getSkillId()));

        return albumConfig;
    }

    /**
     * 获取美女卡册配置
     *
     * @param beautyId 美女ID
     * @return 卡册配置
     */
    public static AlbumConfig getBeautyAlbumConfigInfo(int beautyId) {
        for (AlbumConfig albumConfig : getAlbumConfigMap().values()) {
            if (albumConfig.getBeautyId() == beautyId) {
                return getAlbumInfo(albumConfig.getAlbumId());
            }
        }

        return null;
    }

    /**
     * 获取卡册升级条件
     *
     * @param albumId 卡册ID
     * @param level   当前等级
     * @return 卡册升级条件
     */
    public static Map<Integer, Integer> getAlbumUpgradeCondition(int albumId, int level) {
        Map<Integer, List<Map<Integer, Integer>>> albumUpgradeMap = PatronsMgr.getAlbumUpgradeMap();
        if (albumUpgradeMap.containsKey(albumId)) {
            List<Map<Integer, Integer>> list = albumUpgradeMap.get(albumId);
            if (level < list.size()) {
                return list.get(level);
            }
        }

        return null;
    }

    /**
     * 获取技能额外等级上限
     *
     * @param albumId 卡册ID
     * @param level   卡册等级
     * @param skillId 技能ID
     * @return 技能额外等级上限
     */
    public static int getSkillExtendLevel(int albumId, int level, int skillId) {
        if (level == 0) {
            return 0;
        }
        level--;
        Map<Integer, List<Map<Integer, Integer>>> skillExtendLevelMap = PatronsMgr.getSkillExtendLevelMap();
        if (skillExtendLevelMap.containsKey(albumId)) {
            List<Map<Integer, Integer>> list = skillExtendLevelMap.get(albumId);
            if (level < list.size()) {
                Map<Integer, Integer> levelMap = list.get(level);
                for (Map.Entry<Integer, Integer> kv : levelMap.entrySet()) {
                    if (kv.getKey() == skillId) {
                        return kv.getValue();
                    }
                }
            }
        }

        return 0;
    }

    /**
     * 获取卡牌配置
     *
     * @return Map<Integer, CardConfig>
     */
    public static Map<Integer, CardConfig> getCardConfigMap() {
        return GoodsMgr.getCardConfigMap();
    }

    /**
     * 获取卡册配置
     *
     * @return Map<Integer, AlbumConfig>
     */
    public static Map<Integer, AlbumConfig> getAlbumConfigMap() {
        return PatronsMgr.getAlbumConfigMap();
    }

    /**
     * 获取不同品质卡牌回收的奖励
     *
     * @param quality 品质
     * @return 奖励
     */
    public static String getRecycleRewardByQuality(int quality) {
        if (cardRecycleMap != null) {
            return cardRecycleMap.getOrDefault(quality, null);
        }

        cardRecycleMap = new HashMap<>();
        String recycleStr = GameConfig.TRAVEL_CARD_RECYCLE;

        String[] items = recycleStr.split("\\|");
        for (String item : items) {
            String[] split = item.split(";");
            cardRecycleMap.put(Integer.parseInt(split[0]), split[1]);
        }

        return cardRecycleMap.getOrDefault(quality, null);
    }
}
